home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0049_32Bit unsigned integers.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-21  |  6KB  |  124 lines

  1. {
  2. From: GREG VIGNEAULT
  3. Subj: 32-bit unsigned integers
  4. Does there exist a 32 BIT unsigned (0..xxxx) word in pascal ??
  5. i've got a hexidecimal string (ex. 'E72FAB32') .. now i want to
  6. convert this to a decimal value (not below 0 such as longint and
  7. extended do) so i can devide this by for example 5000000
  8.  
  9.  
  10.  (Note: check at END of code for the required ULONGS.OBJ file)
  11. }
  12.  
  13. (*******************************************************************)
  14. PROGRAM Longs;                      { compiler: Turbo Pascal v4.0+  }
  15.                                     { 18-Nov-93 Greg Vigneault      }
  16. { Purpose: arithmetic functions for unsigned long integers in TP... }
  17. (*-----------------------------------------------------------------*)
  18. { The following external (assembly) functions *MUST* be linked into }
  19. { the main Program, _not_ a Unit.                                   }
  20.  
  21. {$L ULONGS.OBJ}                         { link in the assembly code }
  22. FUNCTION LongADD (Addend1,Addend2:LONGINT):LONGINT;   EXTERNAL;
  23. FUNCTION LongSUB (LongWord,Subtrahend:LONGINT):LONGINT;  EXTERNAL;
  24. FUNCTION LongMUL (Multiplicand,Multiplier:LONGINT):LONGINT; EXTERNAL;
  25. FUNCTION LongDIV (Dividend,Divisor:LONGINT):LONGINT;  EXTERNAL;
  26. FUNCTION LongMOD (Dividend,Divisor:LONGINT):LONGINT;  EXTERNAL;
  27. PROCEDURE WriteULong (LongWord:LONGINT;     { the longword          }
  28.                       Width:BYTE;           { _minimum_ field width }
  29.                       FillChar:CHAR;        { leading space char    }
  30.                       Base:BYTE); EXTERNAL; { number base 2..26     }
  31. (*-----------------------------------------------------------------*)
  32. PROCEDURE TestLongs ( Long1,Long2 :LONGINT;
  33.                       Width       :BYTE;
  34.                       Fill        :CHAR;
  35.                       Base        :BYTE);
  36.       PROCEDURE Reduce1;
  37.         BEGIN
  38.           WriteULong (Long1,1,Fill,10);  Write (',');
  39.           WriteULong (Long2,1,Fill,10);  Write (') result: ');
  40.         END {Reduce1};
  41.       PROCEDURE Reduce2;
  42.         BEGIN
  43.           CASE Base OF
  44.             2  : WriteLn (' binary');   { base 2: binary            }
  45.             10 : WriteLn (' dec');      { base 10: familiar decimal }
  46.             16 : WriteLn (' hex');      { base 16: hexadecimal      }
  47.           END;
  48.         END {Reduce2};
  49.   BEGIN {TestLongs}
  50.       Write ('LongADD (');  Reduce1;
  51.       WriteULong ( LongADD(Long1,Long2),Width,Fill,Base );  Reduce2;
  52.       Write ('LongSUB (');  Reduce1;
  53.       WriteULong ( LongSUB(Long1,Long2),Width,Fill,Base );  Reduce2;
  54.       Write ('LongMUL (');  Reduce1;
  55.       WriteULong ( LongMUL(Long1,Long2),Width,Fill,Base );  Reduce2;
  56.       Write ('LongDIV (');  Reduce1;
  57.       WriteULong ( LongDIV(Long1,Long2),Width,Fill,Base );  Reduce2;
  58.       Write ('LongMOD (');  Reduce1;
  59.       WriteULong ( LongMOD(Long1,Long2),Width,Fill,Base );  Reduce2;
  60.       WriteLn;
  61.   END {TestLongs};
  62. (*-----------------------------------------------------------------*)
  63.  
  64. VAR Long1, Long2  :LONGINT;
  65.     Width, Base   :BYTE;
  66.  
  67. BEGIN
  68.  
  69.   Long1 := 2147483647;
  70.   Long2 := 1073741823;
  71.   Width := 32;
  72.  
  73.   WriteLn;
  74.   FOR Base := 2 TO 16 DO
  75.     IF Base IN [2,10,16] THEN
  76.       TestLongs (Long1,Long2,Width,'_',Base);
  77.  
  78. END.
  79.  
  80. ---------------------------------------------------------------------------
  81.  
  82.  Run this program, it will create ULONGS.ZIP, which contains the
  83.  ULONGS.OBJ file needed for the LongXXX functions...
  84.  
  85. (*********************************************************************)
  86.  PROGRAM A; VAR G:File; CONST V:ARRAY [ 1..701 ] OF BYTE =(
  87. 80,75,3,4,20,0,0,0,8,0,236,50,114,27,51,246,185,93,71,2,0,0,189,3,0,0,
  88. 10,0,0,0,85,76,79,78,71,83,46,79,66,74,189,83,77,104,19,65,20,126,179,
  89. 187,217,196,53,104,67,176,162,1,181,135,10,118,80,212,158,36,151,166,
  90. 110,215,22,154,4,76,119,133,66,75,241,160,23,169,146,102,123,14,132,80,
  91. 233,92,4,65,132,122,8,197,91,142,198,155,212,52,238,138,181,136,157,205,
  92. 65,75,15,5,91,145,18,255,64,76,80,138,248,54,19,17,4,193,147,11,111,190,
  93. 247,190,247,189,111,222,30,38,31,6,205,190,118,125,250,234,204,169,68,
  94. 38,249,228,78,24,64,209,19,99,9,229,124,90,31,234,185,27,132,169,19,32,
  95. 73,164,142,217,192,126,73,150,201,158,91,195,0,82,112,52,157,186,144,
  96. 208,245,9,128,118,154,76,235,5,34,82,125,196,250,218,97,51,230,224,141,
  97. 95,2,115,116,1,64,187,116,113,100,108,200,244,9,0,168,220,84,0,22,9,47,
  98. 157,4,2,255,254,157,45,69,37,9,192,100,239,153,161,244,109,23,171,185,
  99. 36,251,204,12,141,89,225,254,21,246,154,213,250,189,86,243,118,171,57,
  100. 87,207,36,138,85,251,67,209,179,119,152,17,234,219,142,47,207,70,216,
  101. 58,93,102,207,42,210,188,165,190,232,121,211,98,171,21,105,60,255,252,
  102. 116,254,251,185,89,57,95,11,34,247,113,162,166,117,204,153,165,202,70,
  103. 40,106,105,19,181,144,160,52,106,168,217,195,118,8,253,168,161,100,187,
  104. 16,153,133,164,18,179,84,95,68,171,212,107,52,81,186,251,24,128,122,216,
  105. 46,239,93,195,49,60,115,91,180,90,46,211,13,186,66,189,167,42,192,49,
  106. 62,173,242,73,101,166,75,198,34,122,4,99,31,70,55,0,63,142,209,253,59,
  107. 126,32,111,123,172,222,89,2,141,119,255,112,190,239,59,35,143,43,151,
  108. 153,161,150,253,114,105,192,95,166,125,27,118,120,47,55,37,110,42,220,
  109. 84,249,26,175,115,206,189,56,90,103,207,196,209,60,75,227,120,125,182,
  110. 55,142,139,100,143,82,60,99,88,199,176,19,67,77,33,64,10,166,4,5,83,193,
  111. 80,33,101,63,96,1,102,74,127,221,198,150,119,240,215,255,235,66,254,46,
  112. 218,189,6,56,37,32,132,128,179,164,16,226,172,138,252,37,130,12,78,29,
  113. 33,0,206,43,132,32,56,27,162,183,41,122,91,162,247,78,244,26,254,240,
  114. 55,204,15,129,27,65,136,128,75,69,53,136,112,16,220,97,132,3,224,166,
  115. 16,162,224,142,9,201,184,128,73,65,94,22,146,43,98,96,174,61,94,92,192,
  116. 135,164,17,119,81,40,31,9,207,186,144,172,139,129,77,49,254,86,72,26,
  117. 2,62,9,242,139,144,180,218,3,15,231,241,5,228,126,2,80,75,1,2,20,0,20,
  118. 0,0,0,8,0,236,50,114,27,51,246,185,93,71,2,0,0,189,3,0,0,10,0,0,0,0,0,
  119. 0,0,0,0,32,0,0,0,0,0,0,0,85,76,79,78,71,83,46,79,66,74,80,75,5,6,0,0,
  120. 0,0,1,0,1,0,56,0,0,0,111,2,0,0,0,0
  121. ); BEGIN Assign(G,'ULONGS.ZIP'); Rewrite(G,SizeOf(V));
  122.  BlockWrite(G,V,1); Close(G); END {Gbug1.5b}.
  123. (*********************************************************************)
  124.